package pool

import "log"
//具体任务,可以传参可以自定义操作
type Task struct {
	Args interface{}
	Do func(interface{})error
}
//协程的个数
var Nums int
//任务通道
var JobChannels =make(chan Task)
//入口的任务通道
var Jobs =make(chan Task)
//执行
func Run(){
	for i:=0;i<Nums;i++{
		go worker(i)
	}
	for task:=range Jobs{
		JobChannels<-task
	}
	close(JobChannels)
}
//实际的工作协程worker
func worker(workId int){
	for task:=range JobChannels{
		ret:=task.Do(task.Args)
		log.Printf("worker_id:%d , worker_ret:%v\n",workId,ret)
	}
}